import com.google.appengine.api.datastore.*
import static com.google.appengine.api.datastore.FetchOptions.Builder.*

def query = new Query("comment")

query.addSort("pubTime", Query.SortDirection.DESCENDING)

PreparedQuery pq = datastore.prepare(query)

def pageindex = 0

if(params['page']){
	pageindex = ((params['page'] as Integer)- 1)*5
}

def comments = pq.asList(withLimit(5).offset(pageindex))

request.setAttribute 'commentList', comments

request.setAttribute 'page', params['page']== null ? 1 : params['page']

forward "commentList.gtpl"